package com.douqu.game.core.entity;

import com.douqu.game.core.entity.common.CommonData;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;

import java.util.ArrayList;
import java.util.List;

/**
* @author wangzhenfei
*         2017-08-08 16:09
*         副本关卡
*/
public class Level extends GameObject {
    /**
     * 已获取的最高星星数
     */
    private int maxStars;

    /**
     * 是否已经通关过
     */
    private boolean isReceive;

    /**
     * 副本ID
     */
    private int instanceId;

    /** 图标 */
    public String icon;
    /** 地图 */
    public String map;
    /** 头像是否显示 */
    public int showAvatar;
    /** 主将 */
    public int master;
    /** 卡组 */
    public CommonData[] cards;
    /** 道具奖励 */
    public CommonData[] propReward;
    /** 资源奖励 */
    public CommonData[] assetReward;
    /** 解锁关卡 */
    public int unlockLevel;
    /** 宝箱奖励(掉落组ID) */
    public int boxReward;

    /**
     * 评星条件
     */
    public int[] starChecks;




    public int getMaxStars() {
        return maxStars;
    }

    public void setMaxStars(int maxStars) {
        this.maxStars = maxStars;
    }

    public boolean isReceive() {
        return isReceive;
    }

    public void setReceive(boolean isReceive) {
        this.isReceive = isReceive;
    }

    public int getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(int instanceId) {
        this.instanceId = instanceId;
    }

    @Override
    public void copyTo(GameObject obj) {
        super.copyTo(obj);
        Level level = (Level) obj;
        level.maxStars = maxStars;
        level.isReceive = isReceive;
        level.instanceId = instanceId;
        level.icon = icon;
        level.map = map;
        level.master = master;
        level.cards = cards;
        level.propReward = propReward;
        level.assetReward = assetReward;
        level.unlockLevel = unlockLevel;
        level.boxReward = boxReward;
        level.starChecks = starChecks;
    }

    @Override
    public void setVariable(String key, String value)
    {
        if("starChecks".equals(key))
        {
            this.starChecks = LoadUtils.loadIntArray(key, value);
            for(int sc : starChecks)
            {
                if(DataFactory.getInstance().getGameObject(DataFactory.STAR_CHECK_KEY, sc) == null)
                {
                    System.out.println("Level setVariable Error -> starCheck : " + value + " id:" + id);
                }
            }
        }
        else if("cards".equals(key))
        {
            cards = LoadUtils.loadDataToArray(key, value);
            for(CommonData card : cards)
            {
                if(DataFactory.getInstance().getGameObject(DataFactory.CARD_KEY, card.id) == null)
                {
                    System.out.println("Level setVariable Error -> cards : " + value + " id:" + id + " card.id:" + card.id);
                }
            }
        }
        else if("propReward".equals(key))
        {
            propReward = LoadUtils.loadDataToArray(key, value);
            for(CommonData prop : propReward)
            {
                if(DataFactory.getInstance().getGameObject(DataFactory.GOODS_KEY, prop.id) == null)
                {
                    System.out.println("Level setVariable Error -> propReward : " + value + " id:" + id);
                }
                if(prop.value <= 0)
                {
                    System.out.println("Level setVariable Error -> propReward count error : " + value + " id:" + id + " prop.id:" + prop.id);
                }
            }
        }
        else if("assetReward".equals(key))
        {
            assetReward = LoadUtils.loadDataToArray(key, value);
            for(CommonData asset : assetReward)
            {
                if(DataFactory.getInstance().getGameObject(DataFactory.ASSET_KEY, asset.id) == null)
                {
                    System.out.println("Level setVariable Error -> assetReward : " + value + " id:" + id);
                }
                if(asset.value <= 0)
                {
                    System.out.println("Level setVariable Error -> assetReward count error : " + value + " id:" + id + "  asset.id:" + asset.id);
                }
            }
        }
        else if("boxReward".equals(key))
        {
            this.boxReward = Integer.parseInt(value);
            if(DataFactory.getInstance().getGameObject(DataFactory.DROP_GROUP_KEY, boxReward) == null)
            {
                System.out.println("Level setVariable Error -> boxReward : " + value + " id:" + id);
            }
        }
        else
            super.setVariable(key, value);
    }


    @Override
    public String toString() {
        return "Level{" +
                "id = " + id +
                ",maxStars=" + maxStars +
                ",isReceive=" + isReceive +
                '}';
    }
}
